namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class DmFileDataAccess
    {
        private WSDmFileDataAccess.WSDmFileDataAccess wDataAcess = new WSDmFileDataAccess.WSDmFileDataAccess();
        private SmartSoft.DAL.DmFileDataAccess oDataAcess = new SmartSoft.DAL.DmFileDataAccess();

        public DmFileDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public DataTable GetTable()
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table = wDataAcess.GetTable();
            }
            else
            {
                table = oDataAcess.GetTable();
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetTable(object pi_Order, int pi_Type)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetTable(pi_Order, pi_Type);
            }
            else
            {
                table= oDataAcess.GetTable(pi_Order, pi_Type);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public int SaveRow(DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.SaveRow(SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.SaveRow(row);
            }
        }
    }
}